<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
 * Building controller
 */
class Video extends Api_Controller
{
    /**
     * @apiDefine Video 视频
     */
    function __construct()
    {
        // Construct the parent class
        parent::__construct();
        $this->load->model('video_m');
    }

    /**
     * @api               {get} video/index 获取视频列表
     * @apiGroup          Video
     * @apiName           video/index
     * @apiVersion        1.0.0
     * @apiDescription    获取视频列表
     * @apiSampleRequest https://api.bjxpel.cn/api/video/index
     * @apiParam {Int} car_id 车型id
     * @apiParam {Int} [page] 页数,默认1
     * @apiParam {Int} [limit] 页显示数量，默认5
     * @apiSuccess {String} title 标题
     * @apiSuccess {String} pic_url 封面图
     * @apiSuccess {String} link 外链
     * @apiSuccessExample 成功响应
     *          {
     *           "message": "ok",
     *           "code": 200,
     *           "data": null
     *          }
     * @apiErrorExample   失败响应
     *            {
     *             "message": "err",
     *             "code": 0,
     *             "data": null
     *            }
     */
    public function index()
    {
        $car_id = $this->input->get('car_id') ?? 0;
        $page   = $this->input->get('page') ?? 1;
        $limit  = $this->input->get('limit') ?? 5;
        if (!$car_id) {
            return $this->failure(null, "缺少参数车型id");
        }
        $start  = ($page - 1) * $limit;
        $where  = ['car_category' => $car_id, 'deleted' => 0];
        $count  = $this->video_m->total($where);
        $cases  = $this->video_m->select($where, $limit, $start);
        if (!$cases) {
            return $this->failure();
        }
        return $this->success(['total' => $count, 'list' => $cases]);
    }

}